var fs = require("fs"),
  path = require("path"),
  http = require("http");
async = require("async");

var startString = 'var total = {}\n' +
  'var propName = {}\n' +
  'var templateConfig = {}\n' +
  'templateConfig.total = {}\n' +
  'templateConfig.propName = propName\n' +
  'templateConfig.character =  {}\n' +
  'templateConfig.equipment =  {}\n' +
  'templateConfig.prop =  {}\n' +
  'templateConfig.scene =  {}\n' +
  'templateConfig.other =  {}\n' +
  'templateConfig.monster =  {}\n' +
  'templateConfig.strengthen =  {}\n' +
  'templateConfig.skill =  {}\n' +
  'templateConfig.fieldBoss =  {}\n' +
  'templateConfig.lattice =  {}\n' +
  'templateConfig.secretMap =  {}\n' +
  'templateConfig.devilCave =  {}\n' +
  'templateConfig.prefixAttri =  {}\n' +
  'templateConfig.alchemy =  {}'

var endString = 'for (var i in templateConfig) {\n' +
  'var a = templateConfig[i]\n' +
  'for (var templateId in a){\n' +
  'templateConfig.total[templateId] = a[templateId]\n' +
  'if (a[templateId].name) {\n' +
  'propName[templateId] = a[templateId].name\n' +
  '}\n' +
  '}\n' +
  '}'


var startBuff = new Buffer(startString)
var endBuff = new Buffer(endString)

var paths = []
var path = './'
var buffData = new Buffer(0)
var files = fs.readdirSync(path)
files.forEach(function(item) {
  var tmpPath = path + item;
  var stats = fs.statSync(tmpPath)
  if (stats.isDirectory()) {
    var files1 = fs.readdirSync(tmpPath)
    files1.forEach(function(item1) {
      var tmpPath1 = tmpPath + '/' + item1
      paths.push(tmpPath1)
    })
  }
})

var length = 0
var buffData = []
buffData.push(startBuff)
length += startBuff.length
paths.forEach(function(item3) {
  var buffs = fs.readFileSync(item3)
  buffData.push(buffs)
  length += buffs.length
})
buffData.push(endBuff)
length += endBuff.length
fs.writeFile('templateClient.js', Buffer.concat(buffData, length), function(err) {
  if (err) throw err;
  console.log('It\'s saved!'); //文件被保存
});

/*
//所有模板信息
var total = {}
var propName = {} //发送给客户端的信息 id => name
var templateConfig = {}
templateConfig.total = {}
templateConfig.propName = propName
//角色模板信息
templateConfig.character =  {}
//装备模板信息
templateConfig.equipment =  {}
//道具模板信息
templateConfig.prop =  {}
//公共场景模板信息
templateConfig.scene =  {}
//其他配置
templateConfig.other =  {}
//怪物模板信息
templateConfig.monster =  {}
//强化配置
templateConfig.strengthen =  {}
//强化配置
templateConfig.skill =  {}
//野外boss配置
templateConfig.fieldBoss =  {}
//秘境场景
templateConfig.lattice =  {}
//秘境地图
templateConfig.secretMap =  {}
//魔窟
templateConfig.devilCave =  {}
//前缀属性
templateConfig.prefixAttri =  {}
//前缀属性
templateConfig.alchemy =  {}


for (var i in templateConfig) {
  var a = templateConfig[i]
  for (var templateId in a){
    if (a[templateId].name) {
      propName[templateId] = a[templateId].name
    }
  }
}

console.log(propName)
*/
